#include "GameSounds.h"
#include <QCoreApplication>
#include "recource.h"

#ifdef Q_OS_SYMBIAN
#include "sound/playerutility.h"
#endif

GameSounds::GameSounds(QObject *parent) :
    QObject(parent)
{
    init();
}

GameSounds::~GameSounds()
{
#ifdef Q_OS_SYMBIAN
    //    delete m_bgSound;
    for(int i = 0;i < MAX_AUDIOEFFECT;i++)
        delete m_sounds[i];
#endif
}

void GameSounds::init()
{
#ifdef Q_OS_SYMBIAN
    QString path = QCoreApplication::applicationDirPath();
    path.replace("/","\\");

    m_sounds[0] = new PlayerUtility(path + "\\Resources\\go.wav");
    m_sounds[1] = new PlayerUtility(path + "\\Resources\\goal2.wav");
    m_sounds[2] = new PlayerUtility(path + "\\Resources\\goal.wav");

    m_sounds[3] = new PlayerUtility(path + "\\Resources\\hit.wav");
    m_sounds[4] = new PlayerUtility(path + "\\Resources\\hit.wav");
    m_sounds[5] = new PlayerUtility(path + "\\Resources\\hit.wav");
    m_sounds[6] = new PlayerUtility(path + "\\Resources\\hit.wav");
    m_sounds[7] = new PlayerUtility(path + "\\Resources\\hit.wav");

    m_bgSound[0] = new PlayerUtility((path + "\\Resources\\menu.mp3"),true);
    m_bgSound[0]->setLoops(true);
    m_bgSound[0]->setImmediately(Recource::m_bPlaySound);

    m_bgSound[1] = new PlayerUtility((path + "\\Resources\\game.mp3"),true);
    m_bgSound[1]->setLoops(true);
#endif
}

void GameSounds::playBgSound(int index)
{
#ifdef Q_OS_SYMBIAN
    if(index >= 0 && index < MAX_BGSOUND)
        m_bgSound[index]->play();
#endif
}

void GameSounds::stop(int index)
{
#ifdef Q_OS_SYMBIAN
    if(index >= 0 && index < MAX_BGSOUND)
        m_bgSound[index]->stop();
#endif
}

void GameSounds::play(int index)
{
#ifdef Q_OS_SYMBIAN
    if(index >= 0 && index < MAX_AUDIOEFFECT)
        m_sounds[index]->play();
#endif
}

bool GameSounds::IsPlaying(int index)
{
#ifdef Q_OS_SYMBIAN
    if(index >= 0 && index < MAX_BGSOUND)
       return m_bgSound[index]->IsPlaying();
#endif
}
